package edu.sdwu.liqing.qasystem.controller;


import edu.sdwu.liqing.qasystem.entity.QaAnswerComment;
import edu.sdwu.liqing.qasystem.model.Response;
import edu.sdwu.liqing.qasystem.service.IQaAnswerCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 问题回答评论表 entity&QASystem&qa_answer_comment 前端控制器
 * </p>
 *
 * @author liqing@sdwu.edu
 * @since 2020-03-22
 */
@RestController
@RequestMapping("/api/qa-answer-comment")
public class QaAnswerCommentController {

    @Autowired
    IQaAnswerCommentService commentService;

    @PostMapping
    public Response<String> save(@RequestBody QaAnswerComment comment) {
        if (commentService.save(comment)) {
            return Response.ok("评论成功");
        }
        return Response.error("评论失败");
    }

    @PutMapping
    public Response<String> update(@RequestBody QaAnswerComment comment) {
        if (commentService.update(comment)) {
            return Response.ok("评论更新成功");
        }
        return Response.error("评论更新失败");
    }

    @DeleteMapping("{id}")
    public Response<String> delete(@PathVariable("id") String id) {
        if (commentService.delete(id)) {
            return Response.ok("评论删除成功");
        }
        return Response.error("评论删除失败");
    }

    @GetMapping("{answerId}")
    public Response<List<QaAnswerComment>> list(@PathVariable("answerId") String answerId) {
        return Response.ok(commentService.list(answerId));
    }


}

